<?php
defined('EXEC') or die();
function readMenu($menuxml){
	global $pages;
	foreach ($menuxml->li as $li){
		$href = @$li->a['href'];
		$parts = explode('=', $href);
		unset($parts[0]);
		$parts = implode('=', $parts);
		$parts = explode('/', $parts);
		$menuitem = $parts[count($parts) - 1];
		if($menuitem)
			$pages[$menuitem] = array(	'label' => (string) $li->a, 'link' => (string) $href );

		if(@$li->ul){
			readMenu($li->ul);
		}
	}
}
?>
<div id="topo">
    <div id="nome"><?php echo Config::SYSTEM; ?></div>
    <div id="sair"><a data-toggle="modal" href="javascript:void(0);" data-target="#myModal">Sair</button></div>

	<div style="margin-top:5px; float:right; clear:both;">
    	<img src="assets/profile.png" style="float:right; margin-top:20px;"/>

        <ul class="info">
            <li>
                <b>Usuário:</b> <a href="?page=acesso/alterar-senha"><?php echo $user['nm_login']; ?></a>
            </li>
            <li>
                <b>Último Acesso:</b> <?php echo ($user['ultimo_acesso'] ? $user['ultimo_acesso'] : ' - '); ?>
            </li>
            <li>
                <b>Unidade de Trabalho:</b> <?php echo 'MATRIZ'; ?>
            </li>
        </ul>
	</div>
	<br clear="all" />
	<div class="data-hora">
		<img src="assets/icon_date.gif" align="left"/>
		 <?php echo date('d/m/Y - H:i'); ?>
    </div>
</div>
<div id="menu">
	<?php
	ob_start();
	require('includes/menu.php');
	$menuhtml = ob_get_contents();
	ob_end_clean();
	$menuxml = simplexml_load_string($menuhtml, 'SimpleXMLElement', LIBXML_NOCDATA);

	$pages = array();
	readMenu($menuxml);
	echo $menuhtml;
	?>
</div>
<div id="caminho">
	<?php echo @Controller::getLocation($pages); ?>
</div>

<!-- Modal Teste -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" style="width: 400px">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel"><?php echo Config::SYSTEM; ?></h4>
      </div>
      <div class="modal-body">
        <p>Tem certeza que deseja sair?</p>
      </div>
      <div class="modal-footer">
        <button type="button" onclick="window.location = '?logout=1';" class="btn btn-success">Sim</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script type="text/javascript">
$(function(){
	$('#navigation > li').mouseover(function(){
		$(this).find('ul').show();
	}).mouseout(function(){
		$(this).find('ul').hide();
	});
	$('#dialog_logout').dialog({
		autoOpen: false,
		width: 250,
		modal: true,
		buttons: {
			"Ok": function() {
				$(this).dialog("close");
				window.location = '?logout=1';
			},
			"Cancelar": function() {
				$(this).dialog("close");
			}
		}
	});
});
</script>